package cn.mw.cmdb.service.impl;

import cn.mw.cmdb.entity.ItemNameMapperInfo;
import cn.mw.microMonitorCommon.api.cmdb.MwCMDBMonitorApi;
import cn.mw.microMonitorCommon.enums.ServerTypeEnum;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@DubboService
public class MwCMDBMonitorApiImpl implements MwCMDBMonitorApi {

    @Autowired
    private CmdbServiceManage cmdbServiceManage;

    @Override
    public Map<String, String> getMonitorItemNameMap(List<String> itemNames) {
        Map<String, String> itemNameMap = new HashMap<>();
        ItemNameMapperServiceImpl service = (ItemNameMapperServiceImpl) cmdbServiceManage.getModelService(ItemNameMapperServiceImpl.ID);
        try {
            ItemNameMapperInfo mapperInfo=new ItemNameMapperInfo();
            mapperInfo.setItemList(itemNames);
            mapperInfo.setType(ServerTypeEnum.Zabbix.getCode());
            List<ItemNameMapperInfo> itemNameMapperInfoList= service.doSelectList(mapperInfo);
            //item映射中文名称
            itemNameMap = itemNameMapperInfoList.stream().filter(s -> !Strings.isNullOrEmpty(s.getItem())).collect(Collectors.toMap(s -> s.getItem(), s -> s.getDescrCn(), (o1, o2) -> o1));
        }catch (Exception e){
            log.error("parseMonitorItemName error!",e);
        }

        return itemNameMap;
    }
}
